package com.voa.service;

import java.util.Date;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.team4.constants.StringConstant;
import org.team4.dao.DAOFactory;
import org.team4.exception.CRUDException;
import org.team4.service.IService;
import org.team4.util.LoginBean;

import com.voa.dao.BlogReplyDAO;
import com.voa.domain.BlogReply;

/**
 * <p>程序名称：       BlogService.java</p>
 * <p>程序说明：       日志回复服务</p>
 * <p>版权信息：       Copyright 深圳市维远泰克科技有限公司</p>
 * <p>时间：          Feb 11, 2011 11:39:08 AM</p>	
 * 
 * @author：          Marker.King
 * @version：         Ver 0.1
 */
@Service
public class BlogReplyService implements IService {

	private BlogReplyDAO blogReplyDAO;
	
	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		blogReplyDAO = (BlogReplyDAO) DAOFactory.getDAO(sessionFactory, BlogReplyDAO.class);
	}
	
	public BlogReply saveBlogReply(BlogReply blogReply) throws CRUDException {
		blogReply.setCreator(LoginBean.getLoginBean().getUser());
		blogReply.setCreateTime(new Date());
		if(!StringConstant.TRUE.equals(blogReply.getIsPT())) {
			blogReply.setIsPT(StringConstant.FALSE);
		}
		blogReplyDAO.save(blogReply);
		return blogReply;
	}
	
	public void deleteBlogReply(String id) throws CRUDException {
		blogReplyDAO.delete(id);
	}

}
